import java.util.Arrays;
import java.util.Scanner;

class Student implements Comparable<Student> {
    String name;
    long id;
    int age;

    Student(String name, long id, int age) {
        this.name = name;
        this.id = id;
        this.age = age;
    }

    @Override
    public int compareTo(Student obj) {
        if (this.age > obj.age)
            return -1;
        else if (this.age == obj.age) {
            if (this.id > obj.id)
                return 1;
            else if (this.id == obj.id)
                return 0;
            else
                return -1;
        } else
            return 1;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Student[] arr = new Student[n];
        for (int i = 0; i < n; i++) {
            String name = sc.next();
            long id = sc.nextLong();
            int age = sc.nextInt();
            arr[i] = new Student(name, id, age);
        }
        Arrays.sort(arr);
        for (int i = 0; i < n; i++) {
            System.out.println(arr[i].name + " " + arr[i].id + " " + arr[i].age);
        }
    }
}
